package com.swh.controller.Institutional;

import com.github.pagehelper.PageInfo;
import com.swh.entity.QualificationCondition;
import com.swh.entity.SysUser;
import com.swh.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

/**
 * @Author: swh
 * @Description:
 * @Date: 2020/12/28 16:21
 * @Version: 1.0
 */
@Controller
@RequestMapping("/guguanjia/sysuser")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    @RequestMapping("/index")
    public String login() {
        return "/user/user-list";
    }


    @RequestMapping("/toUpdate")
    public String toUpdate() {
        return "/user/user-save";
    }


    @ResponseBody
    @RequestMapping("/selectPage/{pageNum}/{pageSize}")
    public PageInfo<Map> selectPage(@PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize,
                                    QualificationCondition condition) {
        return sysUserService.selectPage(pageNum, pageSize, condition);
    }


    //删除//修改
    @ResponseBody
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public void updateById(@RequestBody SysUser sysUser) {
        sysUserService.update(sysUser);
    }


    //根据id查询并且回写数据
    @ResponseBody
    @RequestMapping("/get")
    public Object get(Integer id) {
        return sysUserService.findById(id);
    }

    //添加
    @ResponseBody
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    public void insert(@RequestBody SysUser sysUser) {
        sysUser.setCreateDate(new Date());
        sysUser.setUpdateDate(new Date());
        sysUser.setDelFlag("0");
        sysUser.setStatus("0");
        sysUserService.insert(sysUser);
    }


}
